//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;

using System.Net;
using System.IO;

using Microsoft.Research.ScientificWorkflow;
using WorkflowData;

namespace Microsoft.Research.ScientificWorkflow.Activities
{
    [Name("Processing")]
    [Description("Waits for n seconds to simulate processing")]
    [WorkflowCategory("NetCdf")]
    public partial class ProcessCurrentValues : System.Workflow.ComponentModel.Activity
    {
        #region Property Definitions
        // Required input property
        public static DependencyProperty InputHyperCubeProperty =
            DependencyProperty.Register("InputHyperCube", typeof(HyperCube), typeof(ProcessCurrentValues));
        // Optional input properties
        public static DependencyProperty TextProperty =
            DependencyProperty.Register("Text", typeof(string), typeof(ProcessCurrentValues),
            new PropertyMetadata(string.Empty, DependencyPropertyOptions.Optional));
        public static DependencyProperty TimeProperty =
            DependencyProperty.Register("Time", typeof(int), typeof(ProcessCurrentValues),
            new PropertyMetadata(3, DependencyPropertyOptions.Optional));
        // Output property
        // Output property
        public static DependencyProperty OutputHyperCubeProperty =
            DependencyProperty.Register("OutputHyperCube", typeof(HyperCube), typeof(ProcessCurrentValues));

        [RequiredInputParam]
        [Name("Input HyperCube", "Input")]
        [Description("Input data in HyperCube format. This is the data that will be processed.")]
        public HyperCube InputHyperCube
        {
            get { return ((HyperCube)(base.GetValue(ProcessCurrentValues.InputHyperCubeProperty))); }
            set { base.SetValue(ProcessCurrentValues.InputHyperCubeProperty, value); }
        }

        [OptionalInputParam]
        [Name("Text")]
        [Description("Text to output upon completion of activity")]
        public string Text
        {
            get { return ((string)(base.GetValue(ProcessCurrentValues.TextProperty))); }
            set { base.SetValue(ProcessCurrentValues.TextProperty, value); }
        }

        [OptionalInputParam]
        [Name("Time")]
        [Description("Time taken to process activity")]
        public int Time
        {
            get { return ((int)(base.GetValue(ProcessCurrentValues.TimeProperty))); }
            set { base.SetValue(ProcessCurrentValues.TimeProperty, value); }
        }

        [OutputParam]
        [Name("Output HyperCube", "Output")]
        [Description("The resulting processed HyperCube data")]
        public HyperCube OutputHyperCube
        {
            get { return ((HyperCube)(base.GetValue(ProcessCurrentValues.OutputHyperCubeProperty))); }
            set { base.SetValue(ProcessCurrentValues.OutputHyperCubeProperty, value); }
        }
        #endregion

        public ProcessCurrentValues()
		{
			//InitializeComponent();
		}

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            if (!string.IsNullOrEmpty(this.Text))
                Console.WriteLine(this.Text);

            System.Threading.Thread.Sleep(this.Time * 1000);

            Console.WriteLine(" - Activity Completed after " + this.Time + " seconds.");

            OutputHyperCube = InputHyperCube;

            return base.Execute(executionContext);
        }
	}
}
